/**
 * Created by Eoly on 2017/2/16.
 * Call http://palerock.cn
 */
var activityDetailPage = angular.module('groupDetailPage', []);


activityDetailPage.filter('beToGroupStatus', function () {
    return function (status) {
        return app.beToGroupStatus(status)
    };
});

/**
 * 活动详情
 */
activityDetailPage.controller('activityDetail', function ($scope, $http) {
    //声明获取的活动对象
    $scope.active = {};

    //获取在列表页储存的团id
    $scope.getTheActiveDetail = function (isRefresh) {
        $scope.activeId = sessionStorage.getItem('ptsc_detail_activeId');
        console.log($scope.activeId);
        if (!$scope.activeId) {
            $.alert("未指活动信息", function () {
                app.backLastPosition();
            });
            return;
        }

        if (!isRefresh) {
            $.showPreloader('请稍候');
        }

        $http(
            {
                method: 'get',
                url: net + "/activities/" + $scope.activeId
            }
        ).then(
            //获取成功
            function (res) {

                if (!isRefresh) {
                    $.hidePreloader();
                }

                if (!res.data.error) {

                    console.log('获取成功');
                    console.log(res);

                    //暂时储存获取的对象
                    var active = res.data.data;
                    active.activityImages = active.activityImages.replace("[", "").replace("]", "").replace(/\"/g, "").split(",");
                   console.log( active.activityImages);
                    for (var i = 0; i < active.activityImages.length; i++)
                    {
                        active.activityImages[i] = net + '/resources/img/' + active.activityImages[i];
                    }
                        //遍历图片地址并加上服务器的url
                    $scope.active = active;
                    console.log( active.activityImages);


                    if (isRefresh) {
                        $.toast('刷新成功', 800, 'refresh-suc');
                        $.pullToRefreshDone('.pull-to-refresh-content');
                    }

                    setTimeout(function () {
                        $(function () {
                            $.initSwiper($('.content'));
                        });
                    }, 500);
                } else {
                    $.alert("错误代码:" + res.data.error + "," + res.data.mes, function () {
                        $.pullToRefreshDone('.pull-to-refresh-content');
                    })
                }

            },
            //获取失败
            function (res) {
                if (!isRefresh) {
                    $.hidePreloader();
                }
                $.alert('网络或设置错误');
            }
        )
    };


});